import axios from "axios";
import {showFailToast} from "vant";

const isDev = process.env.NODE_ENV === 'development'

const request = axios.create({
    baseURL: isDev ? 'http://127.0.0.1:8080/api' : 'http://101.35.50.21:8081/api'
})

request.defaults.withCredentials = true; // 配置为true 表示发送请求的时候携带请求凭证cookie

// 请求拦截器
request.interceptors.request.use(
    // 发送请求之前
    (config) => {
        return config;
    },
    // 处理请求异常
    (error) => {
        return Promise.reject(error);
    }
)

// 响应拦截器
request.interceptors.response.use(
    // 响应前
    (response) => {
        if (response.data.code === 40100){
            showFailToast('未登录')
        }
        return response.data;
    },
    (error)=>{
        return Promise.reject(error);
    }
)

export default request
